# -*- coding: utf-8 -*-

'''
Description: 
'''
# -*- coding: utf-8 -*-

"""
Description:新店铺上传阿拉丁商品
"""
from rj.rjmart.pre_api_ls import pre_api_get as ls_api
from rj.rjmart.pre_api_cx import pre_api_get as cx_api
from rj.锐竞 import RJ_api
from utils.file_operation import save_dict_to_json, load_json_to_dict, generate_groups

from ls.utils import html_processon, replace_img, add_dom_style
import time

ids_list = []
cx = cx_api()
ls = ls_api()
rj = RJ_api()


ids_list = []

img_list = [
    {
        "photo": "https://ls-img-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/first.png"
    },
    {
        "photo": "https://bio-mercury-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/photos%5C2.jpg"
    },
    {
        "photo": "https://bio-mercury-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/photos%5C3.jpg"
    },
    {
        "photo": "https://bio-mercury-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/photos%5C4.jpg"
    },
    {
        "photo": "https://shop-img.rjmart.cn/file/suppfloor/cacfce/25c948cd-51ce-42ef-82d5-2d6981f5c112.png"
    },
]
# 获取 cx 阿拉丁商品列表 id
# for group in rj.official_getProductList(brandIds=[1270], status=3):
#     _group_list = [item["id"] for item in group]
#     ids_list.extend(_group_list)

# save_dict_to_json(ids_list, "pro_list.json")
# ids_list = [item["id"] for item in load_json_to_dict("299_pro_list.json")]

data_list =  load_json_to_dict("data_list.json")


# for group in generate_groups(ids_list):
#     prodes_list = cx.ProductsDetailList(group).json()["data"]
#     time.sleep(1)
#     for item in prodes_list:
#         # item["desc"] = html_processon(item["desc"])
#         # item["brandId"] = 1078
#         # item["photos"] = img_list
#         del item["id"]
#         del item["suppId"]
#         del item["suppName"]
#         for sku in item["skuInfos"]:
#             del sku["id"]
#             del sku["differentPrices"]
#             sku["carryFeeTemplateId"] = 7114
#         # item["photos"] = replace_img(item["photos"], item["code"])
#     res = ls.batchSaveOrUpdateProductV2(prodes_list)
#     print(res.json())


for item in data_list:
    for sku in item["skuInfos"]:
        sku["carryFeeTemplateId"] = 7114


for group in generate_groups(data_list):
    res = ls.batchSaveOrUpdateProductV2(group)
    print(res.json())
    time.sleep(1)